package com.skyyan.netty.jjf.client.handler;

import com.skyyan.netty.jjf.client.MessageHandler;
import com.skyyan.netty.jjf.protocol.Message;
import com.skyyan.netty.jjf.protocol.WaterElectricityPriceQueryMessage;

/**
 * 阶梯水电价查询消息处理器
 */
public class WaterElectricityPriceQueryMessageHandler implements MessageHandler {
    @Override
    public boolean canHandle(Message msg) {
        return msg instanceof WaterElectricityPriceQueryMessage;
    }
    
    @Override
    public void handle(Message msg) {
        if (msg instanceof WaterElectricityPriceQueryMessage.Downlink) {
            WaterElectricityPriceQueryMessage.Downlink downlink = (WaterElectricityPriceQueryMessage.Downlink) msg;
            System.out.println("阶梯水电价查询下行报文:");
            System.out.println("  状态码: 0x" + String.format("%02X", downlink.getStatusCodeBCD()));
            System.out.println("  1阶水价: " + String.format("%.3f", downlink.getWaterPrice1Value() / 1000.0) + "元");
            System.out.println("  2阶水价: " + String.format("%.3f", downlink.getWaterPrice2Value() / 1000.0) + "元");
            System.out.println("  3阶水价: " + String.format("%.3f", downlink.getWaterPrice3Value() / 1000.0) + "元");
            System.out.println("  1阶电价: " + String.format("%.3f", downlink.getTieredPrice1Value() / 1000.0) + "元");
            System.out.println("  2阶电价: " + String.format("%.3f", downlink.getTieredPrice2Value() / 1000.0) + "元");
            System.out.println("  3阶电价: " + String.format("%.3f", downlink.getTieredPrice3Value() / 1000.0) + "元");
        } else {
            System.out.println("阶梯水电价查询上行报文");
        }
    }
}